package com.example.administrator.until;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;

import java.util.TimerTask;

/**
 * Created by Administrator on 2016/11/20 0020.
 * 延时跳转
 */

public class MyTimer extends TimerTask
{

    private static MyTimer object;
    private  Class<? extends AppCompatActivity> nextActivity;
    private AppCompatActivity thisActivity;

    private  MyTimer(Class<? extends AppCompatActivity> nextActivity, AppCompatActivity activity)
    {
        this.nextActivity = nextActivity;

        this.thisActivity = activity;
    }

    public static MyTimer getInition(Class<? extends AppCompatActivity> nextActivity, AppCompatActivity activity)
    {
        return  object =  !(object instanceof MyTimer) ?  new MyTimer(nextActivity, activity) : object;
    }

    @Override
    public void run()
    {

        Intent intent = new Intent(this.thisActivity, this.nextActivity);

        if (object != null)
        {
            object.cancel();
            object = null;
        }

        this.thisActivity.startActivity(intent);

        this.thisActivity.overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);

    }

    public Class<? extends AppCompatActivity> getNextActivity()
    {
        return this.nextActivity;
    }

    public void setNextActivity(Class<? extends AppCompatActivity> object)
    {
        this.nextActivity = object;
    }

    public AppCompatActivity getThisActivity()
    {
        return this.thisActivity;
    }

    public void setThisActivity(AppCompatActivity activity)
    {
        this.thisActivity = activity;
    }
}
